<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Promise</title>
</head>
<body>
<script>
    function demo(msg, t) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve(msg);
            }, t * 1000);
        });
    }

    new Promise((resolve, reject) => {
        resolve('1');
        // throw "err";
    }).then(result => {
        console.log(result);
        return demo('2', 2);
    }, reason => {
        console.log(reason);
    }).then(result => {
        console.log(result);
    }).catch(err => console);

    Promise.all([
        new Promise((resolve, reject) => {
            resolve("parallel-1")
        }),
        new Promise((resolve, reject) => {
            resolve("parallel-2")
        }),
    ]).then(result => {
        console.log(result)
    })
</script>
</body>
</html>